package com.hc.kotlin;

import java.io.IOException;
import java.util.List;

import kotlin.Unit;
import kotlin.jvm.functions.Function1;

public class JavaClass {
    private int jint = 100;
    public String javaf1(){
        return "Hello JavaClass f1()";
    }

    public int getJint() {
        return jint;
    }

    public void exceptionf2() throws IOException {
        throw new IOException("exceptionf2");
    }
    public static void main(String[] args) {
//        System.out.println(KotlinClassKt.kotlinf1());
        System.out.println(KLclass.kotlinf1()); //@JvmName Java调用Kotlin

        KotlinClass kotlinClass = new KotlinClass();
//        List<String> kotlinvar = kotlinClass.getKotlinvar();
        List<String> kotlinvar = kotlinClass.kotlinvar; //@JvmField
        for (String s:kotlinvar) {
            System.out.println(s);
        }

        KLclass.kotlinf2("left foot","right foot");
        KLclass.kotlinf2("left foot"); //@JvmOverloads 方法重载

        System.out.println(KotlinClass.innervar);//@JvmField
        KotlinClass.innerf1(); //@JvmStatic

        JavaClass javaClass = new JavaClass();
        try {
            javaClass.exceptionf2(); //Java IOException必须处理
        } catch (IOException e) {
            System.out.println("catch java exception");
        }
        try {
            KLclass.kotlinf3(); //捕获Kotlin指定异常
        } catch (IOException e) {
            System.out.println("catch kotlin exception");
        }
        Function1<String, Unit> kvar = KLclass.getKvar();
        kvar.invoke("Java execute Kotlin function"); //Java调用Kotlin匿名函数
    }
}
